package ModelLayer;
import java.util.ArrayList;

public class CustomerCon
{
	private static CustomerCon instance;
    private ArrayList<Customer> customerCon;
    private ArrayList<BusinessCustomer> businessCustomerCon;
    
    public static CustomerCon getInstance()
    {
        if(instance == null)
        {
            instance = new CustomerCon();
        }
        return instance;
    }
    
    private CustomerCon()
    {
        customerCon = new ArrayList<Customer>();
        businessCustomerCon = new ArrayList<BusinessCustomer>();
    }
    
    public Customer getCustomer(int id)
    {
    	boolean found = false;
        int i = 0;
        while(i < customerCon.size() && !found)
        {
        	if(customerCon.get(i).getId() == id)
        	{
                found = true;
            }
            else
            {
                i ++;
            }
        }
        if(found)
        {
        	return customerCon.get(i);
        }
        else
        {
        	return null;
        }
    }
    
    public BusinessCustomer getBusinessCustomer(int id)
    {
    	boolean found = false;
        int i = 0;
        while(i < businessCustomerCon.size() && !found)
        {
        	if(businessCustomerCon.get(i).getId() == id)
        	{
                found = true;
            }
            else
            {
                i ++;
            }
        }
        if(found)
        {
        	return businessCustomerCon.get(i);
        }
        else
        {
        	return null;
        }
    }
    
    public ArrayList<Customer> getCustomerCon()
    {
        return customerCon;
    }
    
    public ArrayList<BusinessCustomer> getBusinessCustomerCon()
    {
        return businessCustomerCon;
    }
    
    public void addCustomer(Customer customer)
    {
        customerCon.add(customer);
    }
    
    public void addBusinessCustomer(BusinessCustomer businessCustomer)
    {
    	businessCustomerCon.add(businessCustomer);
    }
    
    public void removeCustomer(int id)
    {
        Customer tempCustomer = getCustomer(id);
        if(tempCustomer != null)
        {
            customerCon.remove(tempCustomer);
        }
        
    }
    
    public void removeBusinessCustomer(int id)
    {
        BusinessCustomer tempBusiness = getBusinessCustomer(id);
        if(tempBusiness != null)
        {
            businessCustomerCon.remove(tempBusiness);
        }
    }
}
